/*
 Copyright 2012 Ronald Pablos 

 Licensed under the Apache License, Version 2.0 (the "License");
 you may not use this file except in compliance with the License.
 You may obtain a copy of the License at

 http://www.apache.org/licenses/LICENSE-2.0

 Unless required by applicable law or agreed to in writing, software
 distributed under the License is distributed on an "AS IS" BASIS,
 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 See the License for the specific language governing permissions and
 limitations under the License.
 */
package org.bn.types;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 *
 * @author Ronald
 */
public class DateTime {
    static Pattern p = Pattern.compile("(\\d{4})-?(\\d{2})-?(\\d{2})T?(\\d{2}):?(\\d{2}):?(\\d{2})");
    Date date;
    TimeOfDay time;
    
    public DateTime(int year, int month, int day,int hour, int min,int seg) {
        this.date = new Date(year, month, day);
        this.time = new TimeOfDay(hour, min, seg);
    }
    public DateTime(Date date, TimeOfDay time) {
        this.date = date;
        this.time = time;
    }
    public DateTime(String theDateTime) {
        Matcher m = p.matcher(theDateTime);
        if (!m.matches())
            throw new IllegalArgumentException("DateTime string is not the format YYYY-MM-DDTHH:mm:ss");
        
        this.date = new Date(Integer.parseInt(m.group(1)),Integer.parseInt(m.group(2)),Integer.parseInt(m.group(3)));
        this.time = new TimeOfDay(Integer.parseInt(m.group(4)),Integer.parseInt(m.group(5)),Integer.parseInt(m.group(6)));
    }

    public Date getDate() {
        return date;
    }

    public TimeOfDay getTime() {
        return time;
    }

    public void setDate(Date date) {
        this.date = date;
    }

    public void setTime(TimeOfDay time) {
        this.time = time;
    }

    

 

    @Override
    public String toString() {
        return date.toString()+"T"+time.toString();
        
    }
    
}
